<template>
  <div id="app">
    <div>如果跳转失败失败,请刷新页面</div>
  </div>
</template>

<script>
//获取参数
function GetParam() {  
  var url = window.location.search; //获取url中"?"符后的字串  
  var param = {};  
  if (url.indexOf("?") != -1) {  
      let  str = url.substr(1);  
      let strs = str.split("&");  
      for(var i = 0; i < strs.length; i ++) {  
        param[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);  
      }  
  }  
  return param;  
}


export default {
  name: 'app',
  created () {
    let option = GetParam()
    if(!option.hasOwnProperty('uid')){
      this.$alert('链接错误,请重现复制链接',{
        confirmButtonText: '确定',
      })
      return
    }
    let app_url = option.app_url
    let dataToSend = {
      uid: option.uid,
      page_game_id: option.page_game_id
    }

    this.axios({
      url: this.env + '/start_open_game',
      method:'post',
      data: dataToSend
    }).then((res) => {
      console.log('res1:',res)
    })

    this.$confirm('是否跳转APP Store?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'success'
    }).then(() => {
      this.axios({
        url:this.env + '/open_game',
        data:dataToSend,
        method: 'post'
      }).then((res) => {

        window.location.href = option.app_url
      })
    }).catch(() => {
      this.$message({
        type: 'info',
        message: '已取消跳转,如要跳转请刷新本页面'
      });          
    });
    
  },
}
</script>

<style>
#app {
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
